package insight.Builder;

/**
 * @author huu
 * @create 2025-08-26-14:38
 * @description: 建造者模式最基本的，需求希望在创建User对象时，
 * 传入参数，自动启用校验逻辑并返回User对象
 */
public class User1 {
    private String name;
    private int age;
    public User1(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public static class Builder {
        private String name;
        private int age;
        public Builder(String name, int age) {
            if(name.length() > 3){
                throw new IllegalArgumentException("name is too long");
            }else if(age < 0 || age > 100){
                throw new IllegalArgumentException("age is out of range");
            }else {
                this.name = name;
                this.age = age;
            }
        }
        public void setName(String name) {
            this.name = name;
        }
        public void setAge(int age) {
            this.age = age;
        }
        public User1 build() {
            return new User1(name, age);
        }
    }

}
